import { Component, OnInit } from '@angular/core';
import {Router} from "@angular/router";
import { ActivatedRoute } from "@angular/router"
import {CanComponentLeave} from "../guards/leave.guard";
@Component({
  selector: 'app-router',
  templateUrl: './router.component.html',
  styles: [
  ]
})
export class RouterComponent implements OnInit,CanComponentLeave {
  constructor(private router: Router,private route: ActivatedRoute) { }
  val : string | null = "";
  ngOnInit(): void {
    console.log(this.route.snapshot.data['user']);
    this.route.queryParamMap.subscribe(query => {
      this.val = query.get("name");
    })
  }

  onLeftClick() : void{
    this.router.navigate(['home']);
  }

  canLeave(): boolean {
    if (true) {
      if (window.confirm("有数据未保存, 确定要离开吗")) {
        return true
      } else {
        return false
      }
    }
    return true
  }
}
